package com.jiyi.common;

import android.content.Context;

import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;

public abstract class StringInterface {
    public Context mContext;
    public static Listener<String> mListener;
    public static ErrorListener mErrorListtener;

    public StringInterface(Context context) {
        this.mContext = context;
    }

    public abstract void stringSuccess(String result);
    public abstract void stringError(VolleyError error);
    

    public Listener<String> stringListener() {
        mListener = new Listener<String>() {

            @Override
            public void onResponse(String result) {
            	//正式环境会有返回乱码，原因不明，这里做个过滤
            	if (result.contains("ï»¿")) {
            		result = result.replace("ï»¿", "");
				}
//            	if (result.contains("尚未登录")) {
//            		ToastUtil.getInstances().showMsg("尚未登录或该用户在其他地方登录，请重新登录！");
//            		//清除环信登录
//					UserHelp.getInstance().clearUser(AppBase.Context, true);
//					return;
//				}
            	stringSuccess(result);
            }
        };
        return mListener;
    }

    
    
    public ErrorListener errorListener() {
        mErrorListtener = new ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
            	stringError(error);
            }
        };
        return mErrorListtener;
    }
}
